﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Xeot.Utility.Nacha
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

		private void wMain_Loaded(object sender, RoutedEventArgs e)
		{

		}

        private void btnGenerateFile_Click(object sender, RoutedEventArgs e)
        {
			Xeot.Library.Nacha.NachaFile file = new Library.Nacha.NachaFile("Our connection string goes here");
			try
			{
				file.OurCompanyNameLong = txtCompanyNameLong.Text.Trim();
				file.OurCompanyNameShort = txtCompanyNameLong.Text.Trim();
				file.OurRoutingNumber = txtRoutingNumber.Text.Trim();
				file.OurAccountNumber = txtAccountNumber.Text.Trim();
				file.OurBankName = txtBankName.Text.Trim();
				file.ImmediateDestination = txtImmediateDestination.Text.Trim();
				file.ImmediateOrigin = txtImmediateOrigin.Text.Trim();
				file.DailyBatchNumber = txtBatchNumber.Text.Trim();
				//Batch Name
				//Record Description

				file.OurReferenceCode = txtBatchNumber.Text.Trim();
				file.OurDiscretionaryData = txtBatchNumber.Text.Trim();
				file.EntryDescription = txtBatchName.Text.Trim();

				if (!file.GenerateFile())
				{
					//Awwww! Something went wrong!
					return;
				}
				//Success!
				//now we should do something with: file.OurBigFile
			}
			catch (Exception ex)
			{
				throw new Exception("Oh no! Unhandled exception: " + ex.Message);
			}
			finally
			{
				file = null;
			}
        }
    }
}